#include "MallocExclusive.h"
#include "../Utils/PlatTlsUtil.h"
#include <assert.h>

uint32 MallocExclusive::sTlsSlot = GetTlsSlot();

MallocExclusive& MallocExclusive::Get()
{
	MallocExclusive* mallocChest = (MallocExclusive*)::TlsGetValue(sTlsSlot);
	return *mallocChest;
}

MallocExclusive::MallocExclusive() : MallocChest()
{
	// set tls bind this malloc chest
	assert(IsValidTlsSlot(sTlsSlot));
	::TlsSetValue(sTlsSlot, this);
}

MallocExclusive::~MallocExclusive()
{
	// Should not free tls, if free all the thread's malloc will get nullptr
	//assert(IsValidTlsSlot(sTlsSlot));
	//::TlsFree(sTlsSlot);
}
